<template>
  <div>
    <sys-dialog
      :title="addDialog.title"
      :height="addDialog.height"
      :width="addDialog.width"
      :visible="addDialog.visible"
      @onClose="onClose"
      @onConfirm="onConfirm">
      <div slot="content">
        <el-form
          :model="addRoleModule"
          ref="addRoleForm"
          :rules="rules"
          label-width="80px"
          :inline="true"
          size="small">
          <el-form-item prop="name" label="角色名称">
            <el-input v-model="addRoleModule.name"></el-input>
          </el-form-item>
          <el-form-item label="角色备注">
            <el-input v-model="addRoleModule.remark"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </sys-dialog>
  </div>
</template>

<script>
import SysDialog from '@/components/system/SysDialog'
export default {
  components: {
    SysDialog
  },
  data() {
    return {
      //新增或编辑弹框属性
      addDialog: {
        title: '',
        height: 150,
        width: 610,
        visible: false
      },
      //新增或编辑表单数据域
      addRoleModule: {
        id: '', //编辑时候使用
        editType: '', //标识新增或编辑  0：新增 1：编辑
        name: '',
        remark: '',
        createUser: this.$store.getters.userId
      },
      //表单验证
      rules: {
        name: [
          {
            required: true,
            trigger: 'change',
            message: '请填写角色名称'
          }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    show(type, val) {
      //清空表单数据
      this.$resetForm('addRoleForm', this.addRoleModule)
      this.addRoleModule.editType = type
      //设置弹框属性
      if (type === '0') {
        this.addDialog.title = '新增角色'
      } else {
        this.addDialog.title = '编辑角色'
        //把当前点击的行数据复制到表单数据域
        this.$objCoppy(val, this.addRoleModule)
      }
      this.addDialog.visible = true
    },
    // 对话框的事件
    //新增或编辑关闭事件
    onClose() {
      this.$resetForm('addRoleForm', this.addRoleModule)
      this.addDialog.visible = false
    },
    //新增或编辑确认事件
    onConfirm() {
      this.$refs.addRoleForm.validate(async (valid) => {
        if (valid) {
          this.$emit('onConfirm', this.addRoleModule)
          this.addDialog.visible = false
        }
      })
    }
  }
}
</script>
<style lang="less" scoped></style>
